package db

import (
	"git.oschina.net/fanbuchi/timemaker/models"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {
	mysqluser := beego.AppConfig.String("mysqluser")
	mysqlpass := beego.AppConfig.String("mysqlpass")
	mysqlurls := beego.AppConfig.String("mysqlurls")
	mysqldb := beego.AppConfig.String("mysqldb")
	// set default database
	orm.RegisterDataBase("default", "mysql", mysqluser+":"+mysqlpass+"@"+mysqlurls+"/"+mysqldb+"?charset=utf8&loc=Asia%2FShanghai", 30)
	// register model
	orm.RegisterModel(new(models.Profile),
		new(models.Task),
		new(models.ClientToken),
		new(models.ClientDetails),
		new(models.Msg),
		new(models.Version),
	)
	// create table
	orm.RunSyncdb("default", false, true)

}
